package com.bailong.administrator.ausedcar.ui.brand;

import android.os.Handler;
import android.util.Log;

import com.bailong.administrator.ausedcar.bean.HomeLikeBean;
import com.bailong.administrator.ausedcar.config.UrlConfig;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/9/6.
 */
public class BrandPresenter implements BrandContract.Presenter {
    private BrandContract.Mode mode;
    private BrandContract.View view;
    private String brandid;


    public BrandPresenter(BrandContract.View view,String brandid) {
        this.view = view;
        this.mode = new BrandMode();
        this.brandid=brandid;

    }

    @Override
    public void loadHomeLikeBean(int position) {
        HashMap<String, String> hashMap = new HashMap<>();
        switch (position){
            case 0:
                hashMap.put(UrlConfig.parmas._apikey,"fc5e51");
                break;
            case 1:
                hashMap.put(UrlConfig.parmas._apikey,"32b072");
                break;
            case 2:
                hashMap.put(UrlConfig.parmas._apikey,"431ac4");
                break;
            case 3:
                hashMap.put(UrlConfig.parmas._apikey,"6262de");
                break;
            case 4:
                hashMap.put(UrlConfig.parmas._apikey,"75e5ec");
                break;
        }

        hashMap.put(UrlConfig.parmas.brandid, brandid);
        hashMap.put(UrlConfig.parmas.appver, UrlConfig.HomeLikeValues.appver);
        hashMap.put(UrlConfig.parmas.channel, UrlConfig.HomeLikeValues.channel);
        hashMap.put(UrlConfig.parmas.cityid, UrlConfig.HomeLikeValues.cityid);
        hashMap.put(UrlConfig.parmas.nb, UrlConfig.HomeLikeValues.nb);
        hashMap.put(UrlConfig.parmas.os, UrlConfig.HomeLikeValues.os);
        hashMap.put(UrlConfig.parmas.limit, UrlConfig.BuyCarsValues.limit);
        hashMap.put(UrlConfig.parmas.offset, UrlConfig.BuyCarsValues.offset);
        hashMap.put(UrlConfig.parmas.search_cityid, UrlConfig.BuyCarsValues.search_cityid);
        Log.i("jerry", "lo=========== "+hashMap);
        mode.loadHomeLikeBean(new Callback<HomeLikeBean>() {
            @Override
            public void onResponse(Call<HomeLikeBean> call, Response<HomeLikeBean> response) {
                Log.i("jerry", "onResponse:=============zhixing ");
                if (response.isSuccessful()) {
                    final HomeLikeBean body = response.body();
                    Handler handler = new Handler();

                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            view.onResponse(body);

                        }
                    });

                }
            }

            @Override
            public void onFailure(Call<HomeLikeBean> call, Throwable t) {

            }
        }, hashMap);
    }

}
